package com.hust.hui.quick.web.api;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by yihui on 2017/7/12.
 */
@Controller
@Slf4j
public class IndexController {

    @RequestMapping(value = "/hello", method = {RequestMethod.GET})
    @ResponseBody
    public String hello(HttpServletRequest request) {
        return "hello " + request.getParameter("name");
    }


    @RequestMapping(value = "/", method = {RequestMethod.GET})
    public String index(Model model, HttpServletRequest request) {
        model.addAttribute("name", request.getParameter("name"));
        log.info("hello!");
        return "index";
    }


    @RequestMapping(value = "/exec", method = {RequestMethod.GET})
    @ResponseBody
    public void exception(HttpServletRequest request) {
        throw new IllegalArgumentException("some error! params: " + request.getParameterMap());
    }
}
